<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>软件升级流程</title>
    <style>
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 20px;
            color: #333;
        }
        .container {
            width: 100%;
            max-width: 1200px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            margin: 20px 0;
        }
        header {
            background: linear-gradient(90deg, #3498db, #2980b9);
            color: white;
            padding: 20px;
            text-align: center;
        }
        h1 {
            font-size: 28px;
            margin-bottom: 10px;
        }
        .description {
            font-size: 16px;
            opacity: 0.9;
        }
        .flow-container {
            display: flex;
            flex-direction: column;
            padding: 20px;
        }
        .phase {
            margin-bottom: 30px;
            border-left: 3px solid #3498db;
            padding-left: 20px;
            position: relative;
        }
        .phase-title {
            font-size: 20px;
            color: #3498db;
            margin-bottom: 15px;
            padding: 5px 0;
            position: relative;
            left: -23px;
            background: white;
            display: inline-block;
            padding-right: 15px;
        }
        .phase-title::before {
            content: '';
            position: absolute;
            left: -8px;
            top: 50%;
            transform: translateY(-50%);
            width: 16px;
            height: 16px;
            background: #3498db;
            border-radius: 50%;
        }
        .steps {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 15px;
        }
        .step {
            background: #f8f9fa;
            border-radius: 8px;
            padding: 15px;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
            border-left: 4px solid #3498db;
            transition: all 0.3s ease;
        }
        .step:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
        }
        .step-number {
            display: inline-block;
            width: 28px;
            height: 28px;
            background: #3498db;
            color: white;
            border-radius: 50%;
            text-align: center;
            line-height: 28px;
            margin-right: 10px;
            font-weight: bold;
        }
        .step-title {
            font-size: 16px;
            font-weight: 600;
            margin-bottom: 8px;
            color: #2c3e50;
        }
        .step-desc {
            font-size: 14px;
            color: #7f8c8d;
            line-height: 1.5;
        }
        .status {
            display: inline-block;
            padding: 3px 8px;
            border-radius: 4px;
            font-size: 12px;
            font-weight: 500;
            margin-top: 8px;
        }
        .status-starting {
            background: #d6eaf8;
            color: #2e86c1;
        }
        .status-success {
            background: #d5f5e3;
            color: #27ae60;
        }
        .status-failed {
            background: #fadbd8;
            color: #e74c3c;
        }
        .status-warning {
            background: #fdebd0;
            color: #f39c12;
        }
        .status-downloading {
            background: #d6eaf8;
            color: #2e86c1;
        }
        .controls {
            display: flex;
            justify-content: center;
            gap: 15px;
            padding: 20px;
            background: #f8f9fa;
            border-top: 1px solid #e9ecef;
        }
        button {
            padding: 12px 25px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        .btn-start {
            background: #3498db;
            color: white;
        }
        .btn-start:hover {
            background: #2980b9;
        }
        .btn-pause {
            background: #f39c12;
            color: white;
        }
        .btn-pause:hover {
            background: #e67e22;
        }
        .btn-reset {
            background: #e74c3c;
            color: white;
        }
        .btn-reset:hover {
            background: #c0392b;
        }
        .progress-container {
            padding: 0 20px 20px;
            background: #f8f9fa;
        }
        .progress-bar {
            height: 10px;
            background: #ecf0f1;
            border-radius: 5px;
            overflow: hidden;
        }
        .progress {
            height: 100%;
            background: linear-gradient(90deg, #3498db, #2ecc71);
            width: 0%;
            transition: width 0.5s ease;
        }
        .progress-labels {
            display: flex;
            justify-content: space-between;
            margin-top: 10px;
            font-size: 14px;
            color: #7f8c8d;
        }
        .active {
            border-left: 4px solid #2ecc71;
            background: #f0fdf4;
        }
        .completed {
            border-left: 4px solid #27ae60;
        }
        .error {
            border-left: 4px solid #e74c3c;
        }
        @media (max-width: 768px) {
            .steps {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header>
            <h1>软件升级流程</h1>
            <p class="description">可视化展示软件自动升级的完整过程与状态变化</p>
        </header>
        
        <div class="flow-container">
            <div class="phase">
                <h2 class="phase-title">初始化阶段</h2>
                <div class="steps">
                    <div class="step active" id="step1">
                        <div class="step-title"><span class="step-number">1</span>启动升级程序</div>
                        <p class="step-desc">初始化升级状态UpgradeStatus为Starting，从LocalUpgrade.ini读取配置信息</p>
                        <span class="status status-starting">Starting</span>
                    </div>
                </div>
            </div>
            
            <div class="phase">
                <h2 class="phase-title">版本检查阶段</h2>
                <div class="steps">
                    <div class="step" id="step2">
                        <div class="step-title"><span class="step-number">2</span>获取版本配置</div>
                        <p class="step-desc">向升级服务器发送HTTP GET请求，获取Upgrade.ini配置文件</p>
                    </div>
                    <div class="step" id="step3">
                        <div class="step-title"><span class="step-number">3</span>获取失败处理</div>
                        <p class="step-desc">记录升级状态UpgradeStatus为PreUpgradeFailed，退出升级程序</p>
                        <span class="status status-failed">PreUpgradeFailed</span>
                    </div>
                    <div class="step" id="step4">
                        <div class="step-title"><span class="step-number">4</span>获取成功</div>
                        <p class="step-desc">记录升级状态UpgradeStatus为PreUpgradeSuccess</p>
                        <span class="status status-success">PreUpgradeSuccess</span>
                    </div>
                    <div class="step" id="step5">
                        <div class="step-title"><span class="step-number">5</span>解析配置文件</div>
                        <p class="step-desc">解析Upgrade.ini，若失败则记录状态为PreUpgradeVersionFailed</p>
                        <span class="status status-failed">PreUpgradeVersionFailed</span>
                    </div>
                    <div class="step" id="step6">
                        <div class="step-title"><span class="step-number">6</span>版本比对</div>
                        <p class="step-desc">将服务器版本与本地版本信息做比对</p>
                    </div>
                    <div class="step" id="step7">
                        <div class="step-title"><span class="step-number">7</span>版本相同</div>
                        <p class="step-desc">记录升级状态为PreUpgradeVersionEqual，退出程序</p>
                        <span class="status status-warning">PreUpgradeVersionEqual</span>
                    </div>
                </div>
            </div>
            
            <div class="phase">
                <h2 class="phase-title">文件下载阶段</h2>
                <div class="steps">
                    <div class="step" id="step8">
                        <div class="step-title"><span class="step-number">8</span>准备下载</div>
                        <p class="step-desc">获取UpgradeFileUrl并写入LocalUpgrade.ini，开始下载版本</p>
                    </div>
                    <div class="step" id="step9">
                        <div class="step-title"><span class="step-number">9</span>HTTP下载</div>
                        <p class="step-desc">通过HTTP请求下载文件，变更状态为Downloading，支持断点续传</p>
                        <span class="status status-downloading">Downloading</span>
                    </div>
                    <div class="step" id="step10">
                        <div class="step-title"><span class="step-number">10</span>FTP下载</div>
                        <p class="step-desc">通过FTP请求下载文件，变更状态为Downloading</p>
                        <span class="status status-downloading">Downloading</span>
                    </div>
                    <div class="step" id="step11">
                        <div class="step-title"><span class="step-number">11</span>完整性校验</div>
                        <p class="step-desc">计算下载文件的MD5，与服务器提供的MD5进行比对</p>
                    </div>
                    <div class="step" id="step12">
                        <div class="step-title"><span class="step-number">12</span>校验失败</div>
                        <p class="step-desc">重新下载（最多5次重试），记录状态为DownloadRetry或DownloadFailed</p>
                        <span class="status status-failed">DownloadFailed</span>
                    </div>
                    <div class="step" id="step13">
                        <div class="step-title"><span class="step-number">13</span>校验成功</div>
                        <p class="step-desc">记录状态为DownloadSuccess，将文件名写入LocalUpgrade.ini</p>
                        <span class="status status-success">DownloadSuccess</span>
                    </div>
                </div>
            </div>
            
            <div class="phase">
                <h2 class="phase-title">安装执行阶段</h2>
                <div class="steps">
                    <div class="step" id="step14">
                        <div class="step-title"><span class="step-number">14</span>检查强制升级</div>
                        <p class="step-desc">从Upgrade.ini获取ForceUpgrade字段进行判断</p>
                    </div>
                    <div class="step" id="step15">
                        <div class="step-title"><span class="step-number">15</span>强制升级</div>
                        <p class="step-desc">停止相关服务，开始安装，记录状态为Upgrading</p>
                        <span class="status status-downloading">Upgrading</span>
                    </div>
                    <div class="step" id="step16">
                        <div class="step-title"><span class="step-number">16</span>非强制升级</div>
                        <p class="step-desc">用户可选择退出或推迟升级，记录状态为UpgradeDelay</p>
                        <span class="status status-warning">UpgradeDelay</span>
                    </div>
                    <div class="step" id="step17">
                        <div class="step-title"><span class="step-number">17</span>安装失败</div>
                        <p class="step-desc">变更升级状态为UpgradeFailed</p>
                        <span class="status status-failed">UpgradeFailed</span>
                    </div>
                </div>
            </div>
            
            <div class="phase">
                <h2 class="phase-title">完成阶段</h2>
                <div class="steps">
                    <div class="step" id="step18">
                        <div class="step-title"><span class="step-number">18</span>安装成功</div>
                        <p class="step-desc">变更状态为UpgradeSuccess，检查ForceSystemRestart字段</p>
                        <span class="status status-success">UpgradeSuccess</span>
                    </div>
                    <div class="step" id="step19">
                        <div class="step-title"><span class="step-number">19</span>强制重启系统</div>
                        <p class="step-desc">直接重启系统完成安装</p>
                    </div>
                    <div class="step" id="step20">
                        <div class="step-title"><span class="step-number">20</span>重启服务</div>
                        <p class="step-desc">重启相关服务，保证版本正常运行</p>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="progress-container">
            <div class="progress-bar">
                <div class="progress" id="progress-bar"></div>
            </div>
            <div class="progress-labels">
                <span>0%</span>
                <span id="progress-percentage">0%</span>
                <span>100%</span>
            </div>
        </div>
        
        <div class="controls">
            <button class="btn-start" onclick="startProcess()">开始升级</button>
            <button class="btn-pause" onclick="pauseProcess()">暂停</button>
            <button class="btn-reset" onclick="resetProcess()">重置</button>
        </div>
    </div>

    <script>
        let currentStep = 0;
        const totalSteps = 20;
        let isPaused = false;
        let processInterval;
        
        function startProcess() {
            if (currentStep >= totalSteps) return;
            if (isPaused) {
                isPaused = false;
            } else if (currentStep === 0) {
                // 只在第一次开始时初始化
                currentStep = 1;
                updateProgress();
            }
            
            clearInterval(processInterval);
            processInterval = setInterval(() => {
                if (!isPaused && currentStep < totalSteps) {
                    currentStep++;
                    updateProgress();
                    
                    if (currentStep === totalSteps) {
                        clearInterval(processInterval);
                    }
                }
            }, 1500);
        }
        
        function pauseProcess() {
            isPaused = !isPaused;
            document.querySelector('.btn-pause').textContent = isPaused ? '继续' : '暂停';
        }
        
        function resetProcess() {
            clearInterval(processInterval);
            currentStep = 0;
            isPaused = false;
            document.querySelector('.btn-pause').textContent = '暂停';
            
            // 重置所有步骤的状态
            document.querySelectorAll('.step').forEach(step => {
                step.classList.remove('active', 'completed', 'error');
            });
            
            updateProgress();
        }
        
        function updateProgress() {
            const progressPercentage = (currentStep / totalSteps) * 100;
            document.getElementById('progress-bar').style.width = progressPercentage + '%';
            document.getElementById('progress-percentage').textContent = Math.round(progressPercentage) + '%';
            
            // 更新步骤状态
            document.querySelectorAll('.step').forEach((step, index) => {
                step.classList.remove('active', 'completed', 'error');
                
                if (index + 1 === currentStep) {
                    step.classList.add('active');
                } else if (index + 1 < currentStep) {
                    step.classList.add('completed');
                }
                
                // 模拟一些步骤失败的情况
                if ((index + 1 === 3 || index + 1 === 5 || index + 1 === 7 || 
                     index + 1 === 12 || index + 1 === 17) && 
                    index + 1 < currentStep) {
                    step.classList.add('error');
                }
            });
        }
        
        // 初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 初始状态：只有第一步是活动的
            document.getElementById('step1').classList.add('active');
        });
    </script>
</body>
</html>